package com.HQCourse.result;

import lombok.Data;

//还回统一的处理结果
@Data
public class Result<T> {
    //状态码
   private Integer code;
   //还回状态信息
   private String message;
   //换回的数据
   private T data;
   public Result(){
   }

   //有data数据的处理
   public static<T> Result<T> ok(T data){
         Result<T> result = new Result<>();
         result.setCode(20000);
         result.setMessage("成功");
         result.setData(data);
         return result;
   }

   public static<T> Result<T> fail(T data){
       Result<T> result = new Result<>();
       result.setCode(20001);
       if(data==null){
           result.setMessage("失败");
           result.setData(data);
           return result;
       }
       return result;
   }


    public Result<T> message(String msg){
        this.setMessage(msg);
        return this;
    }

    public Result<T> code(Integer code){
        this.setCode(code);
        return this;
    }
}
